package com.bidevalution.support.util;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
	public static String toString(Object value) {
		return value==null?"":value.toString();
	}
	public static List<String> getParamNameList(String sql) {
		List<String> paramNameList= new ArrayList<String>();
		String regEx=":[\\S]+";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(sql);
		String paramName = "";
		while(m.find()) {
			paramName = m.group();
			if(paramName.indexOf(")") !=-1) {
				paramName = paramName.substring(0,paramName.indexOf(")"));
			}
			paramNameList.add(paramName.substring(1));
		}
		return paramNameList;
	}
	public static List<String> getFormulaParam(String sectionParam) {
		List<String> paramNameList= new ArrayList<String>();
		String regEx="$[\\S]+";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(sectionParam);
		String paramName = "";
		while(m.find()) {
			paramName = m.group();
			if(paramName.indexOf(")") !=-1) {
				paramName = paramName.substring(0,paramName.indexOf(")"));
			}
			paramNameList.add(paramName.substring(1));
		}
		return paramNameList;
	}
	static public String getLenString(String value,int len,String prix) {
		int interval = len-value.length();
		for(int i = 0;i<interval;i++) {
			value = prix+value;
		}
		return value;
	}

	/**
	 * 判断字符串是否为数字
	 * @param str
	 * @return
	 */
	public static boolean isNum(String str) {
		Pattern pattern = Pattern.compile("-?[0-9]+\\.?[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if( !isNum.matches() ){
			//不是数字
			return false;
		}else{
			//是数字
			return true;
		}
	}

	/**
	 * 首字母大写
	 * @param word
	 * @return
	 */
	public static String firstUpperCase(String word) {
		char[] strs = word.toCharArray();
		strs[0] -= 32;
		return new String(strs);
	}
	public static void main(String[] args) {
		System.out.println(getLenString("1",11,"0"));;
	}
}
